data4.13<-read.csv("C:\\Users\\86151\\Desktop\\练习4.13.csv",fileEncoding ="GBK")
data4.13
#C:\\Users\\86151\\Desktop\\练习4.13.csv
#C:\\Users\\Administrator\\Desktop\\练习4.13.csv
#1用普通最小二乘法建立回归方程
lm4.13<-lm(y~x,data=data4.13)
summary(lm4.13)
#2检验自相关性
#残差图
e<-resid(lm4.13)
attach(data4.13)
plot(x,e)
abline(h=c(0),lty=5)
detach(data4.13)
#DW检验
install.packages("lmtest")
library(lmtest)
library(zoo)
dwtest(lm4.13,alternative="two.sided")
#3迭代法，并建立回归方程
newdata4.13<-read.csv("C:\\Users\\86151\\Desktop\\新数据4.13.csv",fileEncoding ="GBK")
newdata4.13
#C:\\Users\\86151\\Desktop\\新数据4.13.csv
#C:\\Users\\Administrator\\Desktop\\新数据4.13.csv
lm4.13new<-lm(yy~xx,data = newdata4.13)
summary(lm4.13new)
library(lmtest)
library(zoo)
dwtest(lm4.13new,alternative="two.sided")
#4一阶差分法，并建立回归方程
new1data4.13<-read.csv("C:\\Users\\86151\\Desktop\\新数据(1)4.13.csv",fileEncoding ="GBK")
new1data4.13
#C:\\Users\\86151\\Desktop\\新数据(1)4.13.csv
dlm<-lm(dy~dx-1,data = new1data4.13)
summary(dlm)
dwtest(dlm,alternative="two.sided")
de<-resid(dlm)
de




